package edu.scau.hot.web.controller;

import edu.scau.hot.dto.RoomPriceDTO;
import edu.scau.hot.service.IHotCalculateService;
import edu.scau.hot.vo.HotTypeVO;
import org.dozer.DozerBeanMapper;
import org.dozer.Mapper;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

/**
 * Calculate计算控制层 todo
 * 存储计算接口
 *
 * @author PaperEasyCode
 * @since 2022-03-02 18:52:21
 */
@RestController
@RequestMapping("hotCalculate")
public class HotCalculateController{
    /**
     * 服务对象
     */
    @Resource
    private IHotCalculateService hotCalculateService;

    /**
     * 自定义折扣后的计算结果
     *
     * @param percent   自定义折扣比例
     * @param amount    自定义满减额度
     * @param hotTypeVO 前端VO类
     * @return
     */
    @GetMapping("/calculate")
    public ResponseEntity<HotTypeVO> roomPrice(@RequestParam("percent") double percent,@RequestParam("amount") double amount,HotTypeVO hotTypeVO) {
        Mapper dozerMapper = new DozerBeanMapper();
        RoomPriceDTO roomPriceDTO = dozerMapper.map(hotTypeVO,RoomPriceDTO.class);
        return ResponseEntity.ok(hotCalculateService.calculatePrice(roomPriceDTO));
    }

    /**
     * 返回某个房型整月的价格数据
     *
     * @param typeId
     * @param date
     * @return
     */
    @GetMapping("/price")
    public ResponseEntity<double[]> queryAll(@RequestParam("typeId") Integer typeId,@RequestParam(value = "date", required = false) Date date) {
        RoomPriceDTO roomPriceDTO = new RoomPriceDTO();
        roomPriceDTO.setDate(date);
        roomPriceDTO.setTypeId(typeId);
        return ResponseEntity.ok(this.hotCalculateService.getPrice(roomPriceDTO));
    }
}

